/*
 * Copyright Iain Sproat, 2008
 * 
 *
 */

using System;
using NUnit.Framework;

using FreeBase;

namespace FreeBase_Test
{
	/// <summary>
	/// 
	/// </summary>
	/// <remarks>
	/// For security reasons usernames and passwords should not written in code.
	/// For this test to work please ensure you add an app.config file with the following
	/// <appSettings>
	///	<add key="FreebaseUsername" value="YOURUSERNAME" />
	///	<add key="FreebasePassword" value="YOURPASSWORD" />
	/// </appSettings>
	/// </remarks>
	[TestFixture]
	public class IntegrationTestWrite
	{
		string userName = string.Empty;
		string passWord = string.Empty;
		FreebaseClient SUT = null;
		
		[SetUp]
		public void SetUpFixture()
		{
			//#error Please add app.config with <add key="FreebaseUsername" value="YOURUSERNAME" /> and <add key="FreebasePassword" value="YOURPASSWORD" />.  Delete this line when you have done this.
			userName = System.Configuration.ConfigurationManager.AppSettings["FreebaseUserName"];
			passWord = System.Configuration.ConfigurationManager.AppSettings["FreebasePassword"];
			Assert.IsNotNullOrEmpty( userName, "Please ensure you add your own app.config file to this test project with AppSettings with key FreebaseUserName" +
			                        " holding your username - this is for security reasons." );
			Assert.IsNotNullOrEmpty( passWord, "Please ensure you add your own app.config file to this test project with AppSettings with key" +
			                        " FreebasePassword, holding your password - this is for security reasons." );
			SUT = new FreebaseClient( userName, passWord, true );
		}
		[Test]
		public void TestMethod()
		{
			Assert.IsNotNull( SUT );
			SUT.Authenticate();
			Assert.IsNotNull( SUT );
			
			string testQuery = "{\"query\":[{" +
				"\"name\":\"Freebase\"," +
				"\"id\":null" +
				"]}";
			
			string expected = "[{" +
				"\"id\":\"/guid/9202a8c04000641f80000000041ecebd\"," +
				"\"name\":\"Freebase\"," +
				"\"type\":\"/internet/website\"" +
				"}]";
			
			string returned = SUT.Read( testQuery );
			Assert.AreEqual( expected, returned );
			}
	}
}
